package contents

import (
	"github.com/pkg/errors"
	"yizhuoyan/go-study/pdfgo/raw/objects/indirectobject"
)

type PageOrPages struct {
	parent *Pages
	obj    *indirectobject.IndirectObject
}

func NewPageOrPages(parent *Pages, obj *indirectobject.IndirectObject) (*PageOrPages, error) {
	var rst = &PageOrPages{
		parent: parent,
		obj:    obj,
	}
	if rst.IsPages() || rst.IsPage() {
		return rst, nil
	}
	return nil, errors.New("not PageOrPages")
}

func (this *PageOrPages) IsPage() bool {
	dic := this.obj.MustGetDictionary()
	if dic.HasKeyAndNameValue("/Type", pageTypeValueString) {
		return true
	}
	return false
}
func (this *PageOrPages) IsPages() bool {
	dic := this.obj.MustGetDictionary()
	if dic.HasKeyAndNameValue("/Type", pagesTypeValueString) {
		return true
	}
	return false
}
func (this *PageOrPages) AsPage() *Page {
	rst := new(Page)
	if err := rst.ParseFrom(this.parent, this.obj); err != nil {
		panic(errors.Wrapf(err, "PageOrPages.AsPage"))
	}
	return rst
}
func (this *PageOrPages) AsPages() *Pages {
	rst := new(Pages)
	if err := rst.ParseFrom(this.parent, this.obj); err != nil {
		panic(errors.Wrapf(err, "PageOrPages.AsPages"))
	}
	return rst
}
